All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.java.swing.text.DefaultCaret

java.lang.Object
   |
   +----com.sun.java.swing.text.DefaultCaret

public class DefaultCaret
extends Object
implements Caret, Serializable, FocusListener, MouseListener, MouseMotionListener
An implementation of Caret for a view that maps over the entire portion of the model represented (i.e. there are no holes in the area represented) and renders the insert position as a vertical line. The foreground color of the component is the color of the caret and the background color of the component is the color of the selections made by moving the caret. The Highlighter implementation of the associated UI is used to actually render the selection.

Warning: serialized objects of this class will not be compatible with future swing releases. The current serialization support is appropriate for short term storage or RMI between Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.

See Also:
Caret

Variable Index

 o changeEvent
The change event for the model.
 o listenerList
The event listener list.

Constructor Index

 o DefaultCaret()
Constructs a default caret.

Method Index

 o addChangeListener(ChangeListener)
Adds a listener to track whenever the caret position has been changed.
 o adjustVisibility(Rectangle)
Scrolls the associated view (if necessary) to make the caret visible.
 o damage(Rectangle)
Damages the area surrounding the caret to cause it to be repainted.
 o deinstall(JTextComponent)
Called when the UI is being removed from the interface of a JTextComponent.
 o fireStateChanged()
Notifies all listeners that have registered interest for notification on this event type.
 o focusGained(FocusEvent)
Called when the component containing the caret gains focus.
 o focusLost(FocusEvent)
Called when the component containing the caret loses focus.
 o getBlinkRate()
Gets the caret blink rate.
 o getComponent()
Gets the editor component that this caret is for.
 o getDot()
Fetches the current position of the caret.
 o getMagicCaretPosition()
Gets the saved caret position.
 o getMark()
Fetches the current position of the mark.
 o getSelectionPainter()
Gets the painter for the Highlighter.
 o install(JTextComponent)
Called when the UI is being installed into the interface of a JTextComponent.
 o isSelectionVisible()
Checks whether the current selection is visible.
 o isVisible()
Determines if the caret is currently visible.
 o mouseClicked(MouseEvent)
Called when the mouse is clicked.
 o mouseDragged(MouseEvent)
Moves the caret position according to the mouse pointer's current location.
 o mouseEntered(MouseEvent)
Called when the mouse enters a region.
 o mouseExited(MouseEvent)
Called when the mouse exits a region.
 o mouseMoved(MouseEvent)
Called when the mouse is moved.
 o mousePressed(MouseEvent)
Requests focus on the associated text component, and tries to set the cursor position.
 o mouseReleased(MouseEvent)
Called when the mouse is released.
 o moveCaret(MouseEvent)
Tries to move the position of the caret from the coordinates of a mouse event, using viewToModel().
 o moveDot(int)
Moves the caret position to some other position.
 o paint(Graphics)
Renders the caret as a vertical line.
 o positionCaret(MouseEvent)
Tries to set the position of the caret from the coordinates of a mouse event, using viewToModel().
 o removeChangeListener(ChangeListener)
Removes a listener that was tracking caret position changes.
 o setBlinkRate(int)
Sets the caret blink rate.
 o setDot(int)
Sets the caret position and mark to some position.
 o setMagicCaretPosition(Point)
Saves the current caret position.
 o setSelectionVisible(boolean)
Changes the selection visibility.
 o setVisible(boolean)
Sets the caret visibility, and repaints the caret.

Variables

 o listenerList
 protected EventListenerList listenerList
The event listener list.

 o changeEvent
 protected ChangeEvent changeEvent
The change event for the model. Only one ChangeEvent is needed per model instance since the event's only (read-only) state is the source property. The source of events generated here is always "this".

Constructors

 o DefaultCaret
 public DefaultCaret()
Constructs a default caret.

Methods

 o getComponent
 protected final JTextComponent getComponent()
Gets the editor component that this caret is for.

Returns:
the component
 o damage
 protected void damage(Rectangle r)
Damages the area surrounding the caret to cause it to be repainted. If paint() is reimplemented, this method should also be reimplemented.

Parameters:
r - the current location of the caret
See Also:
paint
 o adjustVisibility
 protected void adjustVisibility(Rectangle nloc)
Scrolls the associated view (if necessary) to make the caret visible. Since how this should be done is somewhat of a policy, this method can be reimplemented to change the behavior. By default the scrollRectToVisible method is called on the associated component.

Parameters:
nloc - the new position to scroll to
 o getSelectionPainter
 protected Highlighter. HighlightPainter getSelectionPainter()
Gets the painter for the Highlighter.

Returns:
the painter
 o positionCaret
 protected void positionCaret(MouseEvent e)
Tries to set the position of the caret from the coordinates of a mouse event, using viewToModel().

Parameters:
e - the mouse event
 o moveCaret
 protected void moveCaret(MouseEvent e)
Tries to move the position of the caret from the coordinates of a mouse event, using viewToModel(). This will cause a selection if the dot and mark are different.

Parameters:
e - the mouse event
 o focusGained
 public void focusGained(FocusEvent e)
Called when the component containing the caret gains focus. This is implemented to set the caret to visible if the component is editable, and sets the selection to visible.

Parameters:
e - the focus event
See Also:
focusGained
 o focusLost
 public void focusLost(FocusEvent e)
Called when the component containing the caret loses focus. This is implemented to set the caret to visibility to false, and to set the selection visibility to false.

Parameters:
e - the focus event
See Also:
focusLost
 o mouseClicked
 public void mouseClicked(MouseEvent e)
Called when the mouse is clicked. A double click selects a word, and a triple click the current line.

Parameters:
e - the mouse event
See Also:
mouseClicked
 o mousePressed
 public void mousePressed(MouseEvent e)
Requests focus on the associated text component, and tries to set the cursor position.

Parameters:
e - the mouse event
See Also:
mousePressed
 o mouseReleased
 public void mouseReleased(MouseEvent e)
Called when the mouse is released.

Parameters:
e - the mouse event
See Also:
mouseReleased
 o mouseEntered
 public void mouseEntered(MouseEvent e)
Called when the mouse enters a region.

Parameters:
e - the mouse event
See Also:
mouseEntered
 o mouseExited
 public void mouseExited(MouseEvent e)
Called when the mouse exits a region.

Parameters:
e - the mouse event
See Also:
mouseExited
 o mouseDragged
 public void mouseDragged(MouseEvent e)
Moves the caret position according to the mouse pointer's current location. This effectively extends the selection.

Parameters:
e - the mouse event
See Also:
mouseDragged
 o mouseMoved
 public void mouseMoved(MouseEvent e)
Called when the mouse is moved.

Parameters:
e - the mouse event
See Also:
mouseMoved
 o paint
 public void paint(Graphics g)
Renders the caret as a vertical line. If this is reimplemented the damage method should also be reimplemented as it assumes the shape of the caret is a vertical line. Sets the caret color to the value returned by getCaretColor().

Parameters:
g - the graphics context
See Also:
damage
 o install
 public void install(JTextComponent c)
Called when the UI is being installed into the interface of a JTextComponent. This can be used to gain access to the model that is being navigated by the implementation of this interface. Sets the dot and mark to 0, and establishes document, property change, focus, mouse, and mouse motion listeners.

Parameters:
c - the component
See Also:
install
 o deinstall
 public void deinstall(JTextComponent c)
Called when the UI is being removed from the interface of a JTextComponent. This is used to unregister any listeners that were attached.

Parameters:
c - the component
See Also:
deinstall
 o addChangeListener
 public void addChangeListener(ChangeListener l)
Adds a listener to track whenever the caret position has been changed.

Parameters:
l - the listener
See Also:
addChangeListener
 o removeChangeListener
 public void removeChangeListener(ChangeListener l)
Removes a listener that was tracking caret position changes.

Parameters:
l - the listener
See Also:
removeChangeListener
 o fireStateChanged
 protected void fireStateChanged()
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method. The listener list is processed last to first.

See Also:
EventListenerList
 o setSelectionVisible
 public void setSelectionVisible(boolean vis)
Changes the selection visibility.

Parameters:
vis - the new visibility
 o isSelectionVisible
 public boolean isSelectionVisible()
Checks whether the current selection is visible.

Returns:
true if the selection is visible
 o isVisible
 public boolean isVisible()
Determines if the caret is currently visible.

Returns:
true if visible else false
See Also:
isVisible
 o setVisible
 public void setVisible(boolean e)
Sets the caret visibility, and repaints the caret.

Parameters:
e - the visibility specifier
See Also:
setVisible
 o setBlinkRate
 public void setBlinkRate(int rate)
Sets the caret blink rate.

Parameters:
rate - the rate in milliseconds, 0 to stop blinking
See Also:
setBlinkRate
 o getBlinkRate
 public int getBlinkRate()
Gets the caret blink rate.

Returns:
s the delay in milliseconds. If this is zero the caret will not blink.
See Also:
getBlinkRate
 o getDot
 public int getDot()
Fetches the current position of the caret.

Returns:
the position >= 0
See Also:
getDot
 o getMark
 public int getMark()
Fetches the current position of the mark. If there is a selection, the dot and mark will not be the same.

Returns:
the position >= 0
See Also:
getMark
 o setDot
 public void setDot(int dot)
Sets the caret position and mark to some position. This implicitly sets the selection range to zero.

Parameters:
dot - the position >= 0
See Also:
setDot
 o moveDot
 public void moveDot(int dot)
Moves the caret position to some other position.

Parameters:
dot - the position >= 0
See Also:
moveDot
 o setMagicCaretPosition
 public void setMagicCaretPosition(Point p)
Saves the current caret position. This is used when caret up/down actions occur, moving between lines that have uneven end positions.

Parameters:
p - the position
See Also:
getMagicCaretPosition, UpAction, DownAction
 o getMagicCaretPosition
 public Point getMagicCaretPosition()
Gets the saved caret position.

Returns:
the position see #setMagicCaretPosition

All Packages  Class Hierarchy  This Package  Previous  Next  Index